<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

defined('_JEXEC') or die('Retricted Access');
jimport( 'joomla.application.component.view' );


class jajobboardViewjacandidates extends JAView
{
    /**
     * Display the view
     */
    function display($tmpl = null)
    {
    	global $option;
    	require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'asset'.DS.'rendfield.php');
    	
		$task = JRequest::getVar("task", '');
		switch ($task){			
			case 'resume':	
				
				jajobboardViewjacandidates::displayResume();
				break;	
			case 'user':	
			case 'edit':		
				jajobboardViewjacandidates::displayForm();				
				break;
			default:
				jajobboardViewjacandidates::displayListItems();
		}
		
		parent::display($tmpl);
  	}
  	
  	
  	/**
  	* Display List of items
  	*/
  	function displayListItems(){  		
  		global $mainframe, $option;     
  		
  		$fieldList = &$this->get('FieldList');
  		   
        // get data items
       	$items = &$this->get('Items');  
//       	var_dump($items);

		$pagination = &$this->get('Pagination');
        
        $lists = $this->_getViewLists($fieldList);
        
        $ordering = true;              
                
		// build the html select list
		

        $this->assignRef('items', $items);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('fieldlist', $fieldList);
        $this->assignRef('lists', $lists);
        $this->assignRef('ordering', $ordering );              
  	}
  	
  	/**
  	* Display edit/add Profile
  	*/
  	function displayResume(){  	    
  		global $option;
  		
  	    $item = $this->get('Item');  	
		
		$fieldList = &$this->get('EditFieldList');
		
		$item = parse_content_item($item, $fieldList);		
		$this->assignRef('fieldlist', $fieldList);
  	    $this->assignRef('option', $option);
  	    $this->assignRef('item', $item);
	}	
	
	/**
  	* Display edit/add Employer
  	*/
  	function displayForm(){  	
  		global $option;
  		    
  		$cid		= JRequest::getVar( 'cid', array(0), '', 'array' );
		$edit		= JRequest::getVar('edit',true);
		$me 		= JFactory::getUser();
		JArrayHelper::toInteger($cid, array(0));

		$db 		=& JFactory::getDBO();
		if($edit)
			$user 		=& JUser::getInstance( $cid[0] );
		else
			$user 		=& JUser::getInstance();

		$myuser		=& JFactory::getUser();
		$acl		=& JFactory::getACL();
		
		$this->assignRef('me', 		$me);
		$this->assignRef('user',	$user);
		$this->assignRef('option',	$option);	
	}	

	function &_getViewLists($fieldList)
	{
		global $mainframe, $option;

		$db = &JFactory::getDBO();
		
        $lists['is_hotjob']	= $mainframe->getUserStateFromRequest( $option.".jajobs.is_hotjob",	'is_hotjob',		'',	'cmd' );
        if($lists['is_hotjob']=='') $lists['is_hotjob'] = -1;
		$filter_order		= $mainframe->getUserStateFromRequest( $option.".jacandidates.filter_order",		'filter_order',		'a.created_date',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.".jacandidates.filter_order_Dir",	'filter_order_Dir',	'ASC',			'word' );
		$search				= $mainframe->getUserStateFromRequest( $option.".jacandidates.search",			'search',			'',				'string' );
		$search				= JString::strtolower( $search );        
				
		// table ordering
		$lists['order_Dir']	= $filter_order_Dir;
		$lists['order']		= $filter_order;
		
		/* search filter */
		$lists['search']= $search;
		$item = new stdClass();
		
		foreach ($fieldList as $field){
			if($field->is_on_filter && ($field->field_type=='SELECT'||$field->field_type=='MSELECT')){
				$item->{$field->field_name} = $mainframe->getUserStateFromRequest( $option.".jacandidates.".$field->field_name,   $field->field_name,   '', 'string' );
				$lists['filter'][$field->field_name] = rendfield($item, $field, true,false,true);
			}
		}	

		$lists['published']	= $mainframe->getUserStateFromRequest( $option.".jacandidates.published",	'published',		'',	'cmd' );
		if($lists['published']=='') $lists['published'] = -1;
		
		$lists['approved']	= $mainframe->getUserStateFromRequest( $option.".jacandidates.approved",	'approved',		'',	'cmd' );
		if($lists['approved']=='') $lists['approved'] = -1;
		
        // filter_state
        $lists['option']    = $option;
		
		return $lists;
	}				   			
	
	function menu()
	{
		$task = JRequest::getVar('task', 'user');
		$cid    = JRequest::getVar( 'cid', array(), 'get', 'array' );
		if (!isset($cid[0]))
			$cid = JRequest::getVar('cid');
        JArrayHelper::toInteger($cid);
        if (isset($cid[0]))
        	$cid = $cid[0];
		?>
			<div class="t">
				<div class="t">
					<div class="t"></div>
				</div>
			</div>
			<div class="m">
				<ul id="submenu">
					<li>
						<a href="index.php?option=com_jajobboard&view=jacandidates&task=user&cid[]=<?php echo $cid;?>"class="<?php if($task==null||$task=='user')echo 'active' ?>">
							<?php echo JText::_( 'Membership Details' ); ?>
						</a>
					</li>				
					<li>			
							<a href="index.php?option=com_jajobboard&view=jacandidates&task=resume&cid[]=<?php echo $cid;?>" class="<?php if($task=='resume')echo 'active' ?>" >
								<?php echo JText::_( 'Resume Details' ); ?>
							</a>
					</li>	
					<!--<li>
						<a href="index.php?option=com_jajobboard&view=jatransactions&task=viewbyuser&userid=<?php echo $cid;?>" class="<?php if($task=='viewbyuser')echo 'active' ?>">
							<?php echo JText::_( 'Payment Details' ); ?>
						</a>
					</li>	-->				
				</ul>
				<div class="clr"></div>
			</div>
			<div class="b">
				<div class="b">
					<div class="b"></div>
				</div>
			</div>		
		<?php		
	}	
}
?>